package cn.doitedu.presto.jdbc;

import java.sql.*;
import java.util.Properties;

/**
 * presto  jdbc连接代码示例
 */
public class Demo {
    public static void main(String[] args) throws SQLException {

        String url = "jdbc:presto://h1:8080/hive/doit13";

        Properties properties = new Properties();
        properties.setProperty("user", "root");
        properties.setProperty("SSL", "false");

        Connection conn = DriverManager.getConnection(url, properties);

        Statement stmt = conn.createStatement();

        //show tables
        ResultSet rs = stmt.executeQuery("show tables");

        while(rs.next()){
            String tableName = rs.getString(1);
            System.out.println(tableName);
        }

        // 查询指定日期范围： 2020-03-12 至 2020-03-14  的日活总数
        rs =stmt.executeQuery("select dt,dau_cnts from ads_apl_dau_cube t where province is null and city is null and district is null and appver is null and devicetype is null and dt>='2020-03-12' and dt<='2020-03-14'");
        while(rs.next()){
            String dt = rs.getString(1);
            int cnts = rs.getInt(2);
            System.out.println(dt + "\t" + cnts);
        }

        rs.close();
        stmt.close();
        conn.close();
    }

}
